package cn.woniu.ecommerceplatform.controller;

import cn.woniu.ecommerceplatform.entity.Address;
import cn.woniu.ecommerceplatform.entity.PageQueryParam;
import cn.woniu.ecommerceplatform.service.AddressService;
import cn.woniu.ecommerceplatform.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired(required = false)
    private AddressService addressService;

    @PostMapping("queryAddress")
    @PreAuthorize("hasAnyAuthority('address:query')")
    public ResponseResult<?> queryGoods(@RequestBody PageQueryParam<Address> PageQueryParam) {
        return addressService.queryAddressList(PageQueryParam);
    }

    /**
     * 根据order_id修改地址信息
     * @param address
     * @return
     */
    @PostMapping("updateAddress")
//    @PreAuthorize("hasAnyAuthority('address:update')")
    public ResponseResult<?> updateAddress(@RequestBody Address address){
        return addressService.updateAddress(address);
    }


    @PostMapping("insertAddress")
    @PreAuthorize("hasAnyAuthority('address:insert')")
    public ResponseResult<?> insertAddress(@RequestBody Address address){
        return addressService.insertAddress(address);
    }

    @RequestMapping("queryAddressByOrderId")
    public ResponseResult<?> queryAddressByOrderId(Integer id) {
        return addressService.queryAddressById(id);
    }

    @PostMapping("queryAddressByAccount")
    public ResponseResult<?> queryGoodsByAccount(@RequestBody PageQueryParam<Address> PageQueryParam) {
        return addressService.queryAddressListByAccount(PageQueryParam);
    }


    @PostMapping("updateAllAddress")
    public ResponseResult<?> updateAllAddress(@RequestBody Address address){
        return addressService.updateAllAddress(address);
    }



}
